package day1105.second;

import day1105.common.MyUtil;
import day1105.common.Student;

import java.util.Comparator;
import java.util.List;
import java.util.stream.Collector;

import static day1105.common.MyUtil.printLine;
/**
 * @author Mr.ma
 * @since 2022/11/6 15:25
 **/
public class SortedTest {
    public static void main(String[] args) {
        List<Student> studentList = MyUtil.createStudentList();
        studentList.stream().forEach(System.out::println);
        printLine("按成绩升序排列");
        studentList.stream().sorted((s1,s2) -> s1.getScore().compareTo(s2.getScore())).forEach(System.out::println);
        printLine("按班级、成绩、年龄排序---错误演示");
        studentList.stream().sorted((s1,s2) -> s1.getClazz().compareTo(s2.getClazz()))
                .sorted((s1,s2) -> s1.getScore().compareTo(s2.getScore()))
                .sorted()
                .forEach(System.out::println);
        printLine("按班级、成绩、年龄排序---正确演示");
        studentList.stream().sorted(Comparator.comparing(Student::getClazz)
                    .thenComparing(Student::getScore)
                    .thenComparing(Student::getAge))
                .forEach(System.out::println);
    }
}
